package com.cloud.class04.config;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassDescription:
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2024/4/10 15:36
 */
@Configuration
//下面的value值大小写一定要和consul里面的名字一样，必须一样
//@LoadBalancerClient的作用是给RestTemplate添加负载均衡功能切换为随机策略
// configuration的作用是给RestTemplateConfig添加负载均衡功能切换为随机策略
@LoadBalancerClient(value = "cloud-payment-service", configuration = RestTemplateConfig.class)
public class RestTemplateConfig {
    @Bean
    // 开启负载均衡
    @LoadBalanced//使用LoadBalanced注解赋予RestTemplate负载均衡的能力
    public RestTemplate restTemplate() {
        return new RestTemplate();


    }
}
